package com.hqbzl.c1.rlock;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.LockSupport;
import java.util.concurrent.locks.ReentrantLock;

// 要求t2要在t1之后执行
@Slf4j
public class ThreadPattern3 {
    public static void sleep(long sec) {
        try {
            TimeUnit.SECONDS.sleep(2);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        final Thread t1 = new Thread(() -> {
            log.debug("wait t2 run");
            LockSupport.park();
            log.debug("t1 run");
        }, "t1");


        final Thread t2 = new Thread(() -> {
            log.debug("t2 run");
            LockSupport.unpark(t1);
        }, "t2");
        t2.start();
        sleep(2);
        t1.start();
//        try {
//            TimeUnit.SECONDS.sleep(2);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }

    }

}
